function res = run_iodine_reaction_real(S2O3)

% initial concentration
I = 0.2784          ; % V(1)
S2O8  = 0.0416       ; % V(2)
I2 = 0;         % V(3)
SO4 = 0;        % V(4)
%S2O3 = 0.022;       % V(5)
S4O6 = 0;        %V(6)

[t, V] = ode45(@iodine_reaction, [0,900], [I, S2O8, I2, SO4, S2O3, S4O6]);

plotter(t,[V(:,2) V(:,3) V(:,5)],...%concentration of S2O8, I2, and S2O3
    'Concentration over time for S203, I2 and S2O8','Time (s)', 'Concentration', ...
    ['S208';'I2  ';'S203'],[ [1 0 0];[ 0 1 0]; [0 0 1]])

for i=1:length(t)
    if (V(i,5)<.001)
    res=t(i);
    break;
    end
    if (i==length(t))
        res=t(i);
    end
end
%res=res+81.4553;
end
function res = iodine_reaction(t,V)

I = V(1);
S2O8 = V(2);
I2 = V(3);
SO4 = V(4);
S2O3 = V(5);
S4O6 = V(6);

k1 = 0.0039832;
k2 = 3000;

% 2I + S2O8 -> I2 + 2SO4
% I2 + 2S2O3 -> S4O6 + 2I

r1 = k1 * S2O8;
r2 = k2 * S2O3 * I2;

dIdt = -2*r1 + 2*r2;
dS2O8dt = -r1;
dI2dt = r1 - r2;
dSO4dt = r1;
dS2O3dt = -2*r2;
dS4O6dt = r2;

res = [dIdt ; dS2O8dt ; dI2dt ; dSO4dt ; dS2O3dt ; dS4O6dt];

end
